package cn.ibizlab.odoo.core.odoo_event.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ievent_event_ticket;
import cn.ibizlab.odoo.core.odoo_event.domain.Event_event_ticket;
import cn.ibizlab.odoo.core.odoo_event.filter.Event_event_ticketSearchContext;
import cn.ibizlab.odoo.core.odoo_event.service.IEvent_event_ticketService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[活动入场券] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Event_event_ticketServiceImpl implements IEvent_event_ticketService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ievent_event_ticketClientService event_event_ticketClientService;

    @Override
    public void updateBatch(List<Event_event_ticket> event_event_tickets, int batchSize) {

        //event_event_ticketClientService.updateBatch(event_event_tickets,batchSize) ;

    }

    @Override
    public boolean update(Event_event_ticket event_event_ticket) {
        boolean bOk = false ;
        Ievent_event_ticket clientModel = this.convert2Model(event_event_ticket,null);
        event_event_ticketClientService.update(clientModel) ;
        this.convert2Domain(clientModel,event_event_ticket) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Event_event_ticket get(Integer id) {
        Ievent_event_ticket clientModel = event_event_ticketClientService.createModel();
        clientModel.setId(id);
        event_event_ticketClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Event_event_ticket get(Event_event_ticket event_event_ticket) {
        Event_event_ticket retevent_event_ticket = this.get(event_event_ticket.getId()) ;
    	BeanCopier copier=BeanCopier.create(retevent_event_ticket.getClass(), event_event_ticket.getClass(), false);
        copier.copy(retevent_event_ticket, event_event_ticket, null);
        return event_event_ticket ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //event_event_ticketClientService.removeBatch(event_event_tickets) ;

    }

    @Override
    public void createBatch(List<Event_event_ticket> event_event_tickets, int batchSize) {

                        //event_event_ticketClientService.createBatch(event_event_tickets,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ievent_event_ticket clientModel = event_event_ticketClientService.createModel();
        clientModel.setId(id);
        event_event_ticketClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean create(Event_event_ticket event_event_ticket) {
        boolean bOk = false ;
        Ievent_event_ticket clientModel = this.convert2Model(event_event_ticket,null);
        event_event_ticketClientService.create(clientModel) ;
        this.convert2Domain(clientModel,event_event_ticket);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Event_event_ticket> searchDefault(Event_event_ticketSearchContext context) {
        List<Event_event_ticket> list = new ArrayList<Event_event_ticket>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_event_ticket> clientModelList = event_event_ticketClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_event_ticket clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_event_ticket>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据活动查询
     */
    @Override
    public Page<Event_event_ticket> selectByOdoo_event(Integer id){
        Event_event_ticketSearchContext context = new Event_event_ticketSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_event_ticket> list = new ArrayList<Event_event_ticket>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_event_ticket> clientModelList = event_event_ticketClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_event_ticket clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_event_ticket>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据活动类别查询
     */
    @Override
    public Page<Event_event_ticket> selectByOdoo_event_type(Integer id){
        Event_event_ticketSearchContext context = new Event_event_ticketSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_event_ticket> list = new ArrayList<Event_event_ticket>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_event_ticket> clientModelList = event_event_ticketClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_event_ticket clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_event_ticket>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据产品查询
     */
    @Override
    public Page<Event_event_ticket> selectByOdoo_product(Integer id){
        Event_event_ticketSearchContext context = new Event_event_ticketSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_event_ticket> list = new ArrayList<Event_event_ticket>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_event_ticket> clientModelList = event_event_ticketClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_event_ticket clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_event_ticket>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Event_event_ticket> selectByOdoo_create(Integer id){
        Event_event_ticketSearchContext context = new Event_event_ticketSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_event_ticket> list = new ArrayList<Event_event_ticket>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_event_ticket> clientModelList = event_event_ticketClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_event_ticket clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_event_ticket>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Event_event_ticket> selectByOdoo_write(Integer id){
        Event_event_ticketSearchContext context = new Event_event_ticketSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Event_event_ticket> list = new ArrayList<Event_event_ticket>();
        Page<cn.ibizlab.odoo.core.client.model.Ievent_event_ticket> clientModelList = event_event_ticketClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ievent_event_ticket clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Event_event_ticket>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ievent_event_ticket convert2Model(Event_event_ticket domain , Ievent_event_ticket model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = event_event_ticketClientService.createModel() ;
        }

         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getSeats_availableDirtyFlag())
            model.setSeats_available(domain.getSeats_available());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getPrice_reduce_taxincDirtyFlag())
            model.setPrice_reduce_taxinc(domain.getPrice_reduce_taxinc());
         if(domain.getPrice_reduceDirtyFlag())
            model.setPrice_reduce(domain.getPrice_reduce());
         if(domain.getRegistration_idsDirtyFlag())
            model.setRegistration_ids(domain.getRegistration_ids());
         if(domain.getSeats_unconfirmedDirtyFlag())
            model.setSeats_unconfirmed(domain.getSeats_unconfirmed());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getSeats_reservedDirtyFlag())
            model.setSeats_reserved(domain.getSeats_reserved());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getPriceDirtyFlag())
            model.setPrice(domain.getPrice());
         if(domain.getSeats_usedDirtyFlag())
            model.setSeats_used(domain.getSeats_used());
         if(domain.getDeadlineDirtyFlag())
            model.setDeadline(domain.getDeadline());
         if(domain.getSeats_availabilityDirtyFlag())
            model.setSeats_availability(domain.getSeats_availability());
         if(domain.getIs_expiredDirtyFlag())
            model.setIs_expired(domain.getIs_expired());
         if(domain.getSeats_maxDirtyFlag())
            model.setSeats_max(domain.getSeats_max());
         if(domain.getEvent_type_id_textDirtyFlag())
            model.setEvent_type_id_text(domain.getEvent_type_id_text());
         if(domain.getEvent_id_textDirtyFlag())
            model.setEvent_id_text(domain.getEvent_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getProduct_id_textDirtyFlag())
            model.setProduct_id_text(domain.getProduct_id_text());
         if(domain.getProduct_idDirtyFlag())
            model.setProduct_id(domain.getProduct_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getEvent_idDirtyFlag())
            model.setEvent_id(domain.getEvent_id());
         if(domain.getEvent_type_idDirtyFlag())
            model.setEvent_type_id(domain.getEvent_type_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Event_event_ticket convert2Domain( Ievent_event_ticket model ,Event_event_ticket domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Event_event_ticket();
        }

        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getSeats_availableDirtyFlag())
            domain.setSeats_available(model.getSeats_available());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getPrice_reduce_taxincDirtyFlag())
            domain.setPrice_reduce_taxinc(model.getPrice_reduce_taxinc());
        if(model.getPrice_reduceDirtyFlag())
            domain.setPrice_reduce(model.getPrice_reduce());
        if(model.getRegistration_idsDirtyFlag())
            domain.setRegistration_ids(model.getRegistration_ids());
        if(model.getSeats_unconfirmedDirtyFlag())
            domain.setSeats_unconfirmed(model.getSeats_unconfirmed());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getSeats_reservedDirtyFlag())
            domain.setSeats_reserved(model.getSeats_reserved());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getPriceDirtyFlag())
            domain.setPrice(model.getPrice());
        if(model.getSeats_usedDirtyFlag())
            domain.setSeats_used(model.getSeats_used());
        if(model.getDeadlineDirtyFlag())
            domain.setDeadline(model.getDeadline());
        if(model.getSeats_availabilityDirtyFlag())
            domain.setSeats_availability(model.getSeats_availability());
        if(model.getIs_expiredDirtyFlag())
            domain.setIs_expired(model.getIs_expired());
        if(model.getSeats_maxDirtyFlag())
            domain.setSeats_max(model.getSeats_max());
        if(model.getEvent_type_id_textDirtyFlag())
            domain.setEvent_type_id_text(model.getEvent_type_id_text());
        if(model.getEvent_id_textDirtyFlag())
            domain.setEvent_id_text(model.getEvent_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getProduct_id_textDirtyFlag())
            domain.setProduct_id_text(model.getProduct_id_text());
        if(model.getProduct_idDirtyFlag())
            domain.setProduct_id(model.getProduct_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getEvent_idDirtyFlag())
            domain.setEvent_id(model.getEvent_id());
        if(model.getEvent_type_idDirtyFlag())
            domain.setEvent_type_id(model.getEvent_type_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
